<?php
namespace app\restaurant\model;

use app\BaseModel;
use think\facade\Db;

class Table extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_restaurant_table';


    /**
     * @author chenniang
     * @DataTime: 2021-03-02 13:50
     * @功能说明:二维码
     */
    public function getQrAttr($value,$data){

        if(isset($value)&&isset($data['id'])&&empty($value)&&isset($data['uniacid'])){

            $input['table_id'] = $data['id'];

            $input['key'] = 41;

            $input['type']= 23;

            $qr   = longbingCreateWxCode($data['uniacid'],$input,'pages/user/home');

            if(isset($qr['qr_path'])){

                $qr = transImagesOne($qr ,['qr_path'] ,$data['uniacid']);

                $res  = $this->dataUpdate(['id'=>$data['id']],['qr'=>$qr['qr_path']]);

                $value= $qr['qr_path'];

            }

        }
        return $value;

    }

    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        $data['update_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $data['update_time'] = time();

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis,$page){

        $data = $this->where($dis)->order('id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:43
     * @功能说明:
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2021-03-03 14:22
     * @功能说明:校验门店桌号
     */
    public function checkStoreTable($store_id,$table_id){

        $dis = [

            'store_id' => $store_id,

            'id'       => $table_id
        ];

        //dump($dis);exit;

        $id = $this->where($dis)->value('id');

        return $id;

    }










}